﻿<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
<script type="text/javascript" src="../lib/html5.js"></script>
<script type="text/javascript" src="../lib/respond.min.js"></script>
<script type="text/javascript" src="../lib/PIE_IE678.js"></script>
<![endif]-->
    <link href="../lib/layui/css/layui.css" rel="stylesheet" type="text/css" />
    <link href="../css/H-ui.min.css" rel="stylesheet" type="text/css" />
    <link href="../css/H-ui.admin.css" rel="stylesheet" type="text/css" />
    <link href="../lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />
    <!--[if IE 6]>
<script type="text/javascript" src="../lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
    <title>自加工处理</title>
</head>
<body>

    <div class="pd-5">
        <div class="row cl" id="findfdiv">
            <div class="formControls col-3"></div>
            <div class="formControls col-2">
                <input type="text" class="input-text" placeholder="输入农作物名称" id="findfv1" name="findfv1">
            </div>
             <div class="formControls col-2">
                <input type="text" class="input-text" placeholder="地块" id="finddcinfo" name="finddcinfo">
            </div>
            <!--   <div class="formControls col-3">
                <span class="select-box">
                    <select class="select" size="1" name="findinfofv4" id="findinfofv4">
                        <option value="待入库">待出库</option>
                        <option value="出库中">出库中</option>
                        <option value="已出库">已出库</option>
                        <option value="全部">全部</option>
                    </select></span>
            </div>-->
            <div class="formControls col-3">
                <button onclick="hcrainpage()" class="btn btn-success radius" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 查询</button>
            </div>
        </div>
        <div class="cl pd-5 bg-1 bk-gray mt-5">
            <div class="row cl">
                <div class="formControls col-4"></div>
                <div class="formControls col-2">
                    <input type="text" class="input-text" placeholder="提交说明" id="postdesc" name="postdesc">
                </div>
                <div class="formControls col-3">
                    <a href="javascript:;" onclick="savetotaskstre()" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 提交</a>
                </div>
            </div>
        </div>
        <div id="hcvueapp" class="mt-5 ml-20">
            <div class="panel panel-default" v-for="site in listinfo">
                <div class="panel-header" style="margin: 0px; padding: 0px;">{{ site.fv1 }}--{{ site.fv2 }}</div>
                <div class="panel-body" style="margin: 0px; padding: 0px;">
                    <table class="table table-border table-bordered table-hover">
                        <thead>
                            <tr>
                                <th>任务信息</th>
                                <th>状态</th>
                                <th>领料量</th>
                                <th>已处理</th>
                                <th>处理量</th>
                                <th>
                                    <div v-if="site.subinfo2.length >0">出成包数{{site.subinfo2[0].fv3}}</div>
                                </th>
                                <th>
                                    <div v-if="site.subinfo2.length >1">出成包数{{site.subinfo2[1].fv3}}</div>
                                </th>
                                 <th>
                                    <div v-if="site.subinfo2.length >2">出成包数{{site.subinfo2[2].fv3}}</div>
                                </th>
                                <th>出成量</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr v-for="(worklist,index) in site.subinfo" v-bind:class="{ success: (worklist.hasoutall<=worklist.storeall), 'warning':worklist.hasoutall>=worklist.storeall }">
                                <td>地块：{{ worklist.dkname}}-领料：{{ worklist.dataaddtime.Value}}-采摘：{{ worklist.taskworktime.Value}}</td>
                                <td>{{ worklist.outstate }}-{{ worklist.productstate }}</td>
                                <td>{{ worklist.storeall }}</td>
                                <td>{{ worklist.hasoutall}}</td>
                                <td>
                                    <input class="input-text" :id="worklist.needtodoid" style="width: 80px;" placeholder="处理量" v-model.number="worklist.needtodo" type="number" onkeyup="onchangeneedtodoid(this.id,1);"  />
                                </td>
                                <td>
                                    <div v-if="site.subinfo2.length >0">  <input type="number" :id="worklist.ggcount1id" class="input-text" style="width: 80px;" placeholder="出成数" v-model.number="worklist.ggcount1" onkeyup="onchangeneedtodoid(this.id,2);" /></div>
                                </td>
                                <td>
                                   <div v-if="site.subinfo2.length >1"> <input type="number" :id="worklist.ggcount2id" class="input-text" style="width: 80px;" placeholder="出成数" v-model.number="worklist.ggcount2" onkeyup="onchangeneedtodoid(this.id,3);" /></div>
                                </td>
                                 <td>
                                   <div v-if="site.subinfo2.length >2"> <input type="number" class="input-text" style="width: 80px;" placeholder="出成数" v-model.number="worklist.ggcount3" onkeyup="onchangeneedtodoid(this.id,4);" /></div>
                                </td>
                                <td>
                                    <input type="number" :id="worklist.ggallcountid" class="input-text" style="width: 80px;" placeholder="出成量" v-model.number="worklist.ggallcount"  />
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="mt-5 row">
                <div id="page1"></div>
            </div>
        </div>
    </div>

    <script type="text/javascript" src="../lib/layui/layui2.js"></script>
    <script type="text/javascript" src="../js/vue.min.js"></script>
    <script>
        var hcvueapp = new Vue({
            el: '#hcvueapp',
            data: {
                listinfo: []
            },
            methods: {
                testc: function (e, e1)
                { console.log(e); console.log(e1); }
            },
            computed: {
                fullName: function () {
                    console.log(this);
                    console.log("执行了computed")
                    return "test";
                }
            }

        })
    </script>
    <script src="../hcjsui/Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="../lib/layui/layui.js"></script>
    <script type="text/javascript" src="../lib/layer/1.9.3/layer.js"></script>
    <script type="text/javascript" src="../lib/laypage/1.2/laypage.js"></script>
    <script type="text/javascript" src="../lib/My97DatePicker/WdatePicker.js"></script>
    <script src="../hcjsui/js/_Define.js" type="text/javascript"></script>
    <script type="text/javascript" src="../js/hcui.js"></script>
    <script type="text/javascript" src="../js/hcui_list.js"></script>

    <script type="text/javascript">
        var whereaddinfo = "";
        $(function () {
            spsetBaseNoBt("yw_baseinfo", "id", "yw_baseinfo as T", "*", "#tablelist", "sctaskoutstore", "生产任务管理", "sctaskoutstore");
            hcrainpage(1);
        });
        function onchangeneedtodoid(htmlid, type) {

            hcvueapp.listinfo.forEach(function (e) {
                e.subinfo.forEach(function (list) {
                    //处理量
                    if (type == 1 && e.subinfo2.length > 0) {
                        //  list.ggcount1 = (list.needtodo * 1 * e.subinfo2[0].nv3).toFixed(0);
                    }
                    var gg1 = 0;//
                    var gg2 = 0;
                    var gg3 = 0;
                    if (e.subinfo2.length > 0) {
                        gg1 = e.subinfo2[0].nv1;
                    }
                    if (e.subinfo2.length > 1) {
                        gg2 = e.subinfo2[1].nv1;
                    }
                    if (e.subinfo2.length > 2) {
                        gg3 = e.subinfo2[2].nv1;
                    }
                    list.ggallcount = (gg1 * 1 * list.ggcount1 + gg2 * 1 * list.ggcount2 + gg3 * 1 * list.ggcount3).toFixed(2);


                });
            });
        }
        function savetotaskstre() {
            var needupdate = 0;
            var message = ""; var postworklist = [];
            for (var sp in hcvueapp.listinfo) {
                var subinfo = hcvueapp.listinfo[sp].subinfo;
                message += "<br/> " + hcvueapp.listinfo[sp].fv1 + "[";
                for (var lindex in subinfo) {
                    if (subinfo[lindex].needtodo <= 0) {
                        console.log("不处理--");
                        continue;
                    }
                    needupdate++;
                    message += "(" + subinfo[lindex].needtodo + ")";
                    postworklist.push({ "id": subinfo[lindex].id, "number": subinfo[lindex].needtodo, "info": subinfo[lindex].productname });
                }
                message += "]";
            }
            layer.confirm('确认信息：记录数：' + needupdate + message, {
                btn: ['加工完成入库', '取消'] //按钮
            }, function () {
                //是否库存足够
                hcui_ajaxasync = false;
                hcapipost("../api/Hcrain/PostCheckJGStoreOutOk", postworklist, function (data) {
                    if (data != "ok") {
                        layer.msg("提交失败 " + data, { icon: 2 });
                    }
                    else {
                        savetotaskstreDo();
                    }
                });
            }, function () {
            });
        }
        function savetotaskstreDo() {
            var outguid = NewGuid();
            var needupdate = 0;
            var updatecount = 0;
            for (var sp in hcvueapp.listinfo) {
                var subinfo = hcvueapp.listinfo[sp].subinfo;
                for (var lindex in subinfo) {
                    if (subinfo[lindex].needtodo <= 0) {
                        console.log("不处理--");
                        continue;
                    }
                    var addinfo = "inouttype%加工完成入库$productstate%包装品"
                        + "$gid%" + outguid//批次
                        + "$remarks%" + $("#postdesc").val()//备注
                        + "$outstate%待出库"//默认状态
                        + "$dkid%" + subinfo[lindex].dkid//地块ID
                        + "$dkname%" + subinfo[lindex].dkname//地块编号
                        + "$taskid%" + subinfo[lindex].taskid//任务ID
                        + "$taskno%" + subinfo[lindex].taskno//任务编号 
                        + "$tasklistid%" + subinfo[lindex].tasklistid//采摘明细ID
                        + "$taskworktime%" + subinfo[lindex].taskworktime.Value//采摘时间
                        + "$storehouseid%1$hasoutall%0"//默认初始化
                        + "$productid%" + hcvueapp.listinfo[sp].id//品种ID
                        + "$productname%" + hcvueapp.listinfo[sp].fv1//品种名称
                        + "$csgetpc%" + subinfo[lindex].csgetpc
                        + "$taskfromorgid%" + subinfo[lindex].taskfromorgid
                        + "$taskfromorgname%" + subinfo[lindex].taskfromorgname
                        + "$datafromtable%hsc_task_process_work"
                        + "$datafromkeyid%" + subinfo[lindex].id
                        + "$storealluseall%" + subinfo[lindex].needtodo
                        + "$storefortype1%" + (subinfo[lindex].ggcount1 == "" ? 0 : subinfo[lindex].ggcount1)
                        + "$storefortype2%" + (subinfo[lindex].ggcount2 == "" ? 0 : subinfo[lindex].ggcount2)
                        + "$storefortype3%" + (subinfo[lindex].ggcount3 == "" ? 0 : subinfo[lindex].ggcount3)
                        + "$storeall%" + subinfo[lindex].ggallcount;//入库量/出成量
                    hcui_ajaxasync = false;
                    console.log(addinfo);
                    //出库处理-这里要禁用异步
                    hcdoadd2017("hsc_task_store", addinfo, 1, "", function (info) {
                        //更新记录--已出库
                        if (info == "ok") {
                            updatecount++;
                            hcdoedit("hsc_task_process_work", "id", subinfo[lindex].id, "outstate%处理中$hasoutall%hcrainself(hasoutall+" + subinfo[lindex].needtodo + ")", function (info2) {
                            });
                        }
                        else { layer.msg('处理过程有异常：' + info, { icon: 2 }); }
                    });
                    hcui_ajaxasync = true;
                }
            }
            layer.msg('完成操作，记录数：' + updatecount, { icon: 1 });
            //重新加载 
            if (updatecount > 0) {
                hcrainpage(1);
            }

        }
        function hcrainpage(curr) {
            var finddcno = $("#findfv1").val();
            var findinfofv4 = $("#findinfofv4").val();
            if (finddcno) {
                whereaddinfo = " and fv1 like '%" + finddcno + "%'";
            }
            else { whereaddinfo = ""; }

            var suminfowhere = "";
            var finddcinfo = $("#finddcinfo").val();
            if (finddcinfo) {
                suminfowhere = "dkname-||like||" + finddcinfo + ",";
            }
            else { suminfowhere = ""; }


            $.ajax({
                type: "post",
                url: "../ashx/spui.ashx",
                data: {
                    "action": "getpageinfo",
                    "pagenow": curr || 1,
                    "pagesize": 50,
                    "select": "t.id,t.fv1,t.fv2",
                    "table": "yw_baseinfo as t",
                    "group": "",
                    "having": "",
                    "where": " type=1 and maintype=1 " + whereaddinfo + " and id in(select productid from hsc_task_process_work where   databranchid=" + HCUser.HCUorg + " and storeall>hasoutall)",//有库存的
                    "order": "",
                    "subinfo": "csgetpc,id,taskfromorgid,taskfromorgname,taskid,taskno,tasklistid,productname,dkid,dkname,dataaddtime,storeall,(storeall-hasoutall) as needtodo_old,(storeall-hasoutall) needtodo,CONCAT('needtodo',id) as needtodoid,CONCAT('ggcount1',id) as ggcount1id,CONCAT('ggcount2',id) as ggcount2id,CONCAT('ggallcount',id) as ggallcountid,'' as ggcount1,'' as ggcount2,'' as ggcount3,0 as ggallcount,lockcout,hasoutall,outstate,taskworktime,productstate#hsc_task_process_work#productid-@id,databranchid-" + HCUser.HCUorg + "," + suminfowhere + "storeall-||>||@@hasoutall#id#",//当前机构 当前物品
                    "subinfo2": "id,fv1,fv2,fv3,nv1,nv2,nv3#yw_baseinfo#type-7,fv1-@id#nv2#"//当前机构+7+当前品种
                },
                async: true,
                cache: false,
                error: function (error) {

                },
                success: function (data) {
                    var result = JSON.parse(data);
                    hcvueapp.listinfo = result.data;
                    //if (hcvueapp.listinfo == null || hcvueapp.listinfo.length == 0) {
                    //    result.message = "没有数据";// layer.msg('没有相关数据噢', { icon: 5 });
                    //}
                    //hcvueapp.listinfo.forEach(function (e) {
                    //    e.subinfo.forEach(function (list) {
                    //        list.ggallcount = list.needtodo;
                    //        //e.storeall = e.storeall * 1 + (list.storeall * 1 - list.hasoutall * 1);
                    //    });
                    //});
                    //onchangeneedtodoid(1, 1);
                    //显示分页
                    laypage({
                        cont: 'page1', //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
                        pages: result.message || 0, //通过后台拿到的总页数
                        curr: curr || 1, //当前页
                        jump: function (obj, first) { //触发分页后的回调
                            if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                                hcrainpage(obj.curr);
                            }
                        }
                    });

                }
            });




        };

        //重新加载-重载
        function findreolad(isback) {
            hcrainpage(1);
        }
    </script>
</body>
</html>
